# -*- coding: UTF-8 -*-

class attrdict(object):
	def __init__(self,dict):
		self.__attrdict__ = dict
	
	def __getattribute__(self,attr):
		d = super(xdict,self).__getattribute__('__attrdict__')
		if not d.has_key(attr):
			raise AttributeError, attr
		return d.get(attr)

# Proxy of access members in a overrided dictionary of object.
class attrproxy(object):
	def __init__(self,d,p):
		self.__d__ = d
		self.__p__ = p

	def __getattribute__(self,attr):
		print "get attr" , attr
		if attr == '__d__':
			return super(attrproxy,self).__getattribute__(attr)
		elif attr == '__p__':
			return super(attrproxy,self).__getattribute__(attr)
		d = super(attrproxy,self).__getattribute__('__d__')
		if d.has_key(attr):
			return d[attr]
		p = super(attrproxy,self).__getattribute__('__p__')
		return p.__getattribute__(attr)

	def __setattr__(self,attr,value):
		if attr == '__d__' or attr == '__p__':
			super(attrproxy,self).__setattr__(attr,value)
		else:
			p = super(attrproxy,self).__getattribute__('__p__')
			return p.__setattr__(attr,value)
